#include <iostream>
#include <thread>
#include "krpc/netserver.h"
#include "krpc/service.h"

struct hehe
{
	int a;
	int b;
	MSGPACK_DEFINE(a,b);
};

int main(int argc, char const *argv[])
{
	//KRPC::TS server(9000);
	//KRPC::US server(9000);
	KRPC::LDS server("unix");
	//KRPC::LSS server("unix");
	KRPC::Service service(server);

	std::thread th([&service]{
		std::string str("hello wrold");
		int i = 0;
		while (1) {
			std::this_thread::sleep_for(std::chrono::milliseconds(500));
			service.publish("sub", str, i);
			str[0] += 1;
			i++;
		}
	});
	th.detach();

	std::thread th2([&service]{
		hehe hi;
		hi.a=1;
		hi.b=100;
		while(1) {
			std::this_thread::sleep_for(std::chrono::seconds(1));
			hi.a++;
			hi.b--;
			//service.publish("sub", std::string("hello wrold"), 100);
			service.publish("hehe", hi);
		}
	});
	th2.detach();
	
	std::thread th3([&service]{
		int i = 1;
		while(1) {
			std::this_thread::sleep_for(std::chrono::seconds(2));
			service.publish("hello", "hello", "wrold", i++);
		}
	});
	th3.detach();

	service.run();
	return 0;
}
